package com.shopping.test;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.websocket.Session;

@WebServlet("/Text")
public class Text extends HttpServlet {
	private static final long serialVersionUID = 1L;

    public Text() {
        
    }
    @Override
    public void init() throws ServletException {
    	System.out.println("初始化....");
    }
	//HttpServletRequest类有setAttribute()方法，而没有setParameter()方法
	//一般通过表单和链接的参数使用getParameter,可以得到入id=123之类的
	//setAttribute为元素指定属性和设置值，getAttribute可以得到setAttribute设置的值
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String name=request.getParameter("name");
		HttpSession session=request.getSession(true);
		session.setAttribute("name", name);
		System.out.println(session.getAttribute("name"));
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
